package com.xdwanj.androidutil.volley.request;

import androidx.annotation.Nullable;

import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpHeaderParser;

import java.util.Map;

public class DownloadRequest extends Request<byte[]> {

    private final Response.Listener<byte[]> mListener;

    public Map<String, String> responseHeaders;

    public DownloadRequest(int method, String url, Response.Listener<byte[]> listener, @Nullable Response.ErrorListener errorListener) {
        super(method, url, errorListener);
        setShouldCache(false);
        this.mListener = listener;
    }

    @Override
    protected Response<byte[]> parseNetworkResponse(NetworkResponse response) {

        responseHeaders = response.headers;
        return Response.success(response.data, HttpHeaderParser.parseCacheHeaders(response));

    }

    @Override
    protected void deliverResponse(byte[] response) {
        mListener.onResponse(response);
    }

}